/*******************************************************************************
filename      StringCommentPrinter.RegEx.NonGreedy.cpp
author        Craig Williams

Brief Description:
  Prints all strings, C Style comments, and C++ Style comments from a file.
    If a file is not specified, Parser.c will be processed.

  Non Greedy RegEx version of StringCommentPrinter. The only difference between
    this file and StringCommentPrinter.RegEx.c is the RegEx used to detect
    C style comments. Namely, the current RegEx is far simpler.
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>

#include "Parser.h"

char *PrintString (Parser &p, char *sp, void *);
char *PrintCComment(Parser &p, char *comment, void *unused);
char *PrintCPPComment(Parser &p, char *comment, void *unused);

int main(int argc, char *argv[])
{
  char  *buffer;
  Parser p(0);

    /* Initalize the parser */
  if(argc == 1)
    p.LoadFile("Parser.cpp"); /* No file specified. Assume Parser.cpp       */
  else
    p.LoadFile(argv[1]);    /* Attempt to load what ever is specified   */

  p.Enable(PARSER_REGULAR_EXPRESSIONS);

  if(p.AddTokenSeparator("//[^\n\r]*", 0, -1, 0, PrintCPPComment, 0))
    printf("Compile Error: CPP Style Comment\n");

  if(p.AddTokenSeparator("/\\*.+?\\*/", 0, -1, 0, PrintCComment, 0))
    printf("Compile Error: C Style Comment\n");

  if(p.AddTokenSeparator("\"([^\"\\]|\\\\.)*\"", 0, -1, 0, PrintString, 0))
    printf("Compile Error: String\n");

  for(buffer = p.GrabToken(); buffer; buffer = p.GrabToken())
    free(buffer);

  return 0;
}

char *PrintString(Parser &p, char *sp, void *unused)
{
  printf("String Found!\n%s\n\n", sp);

  return sp;  /* Don't return the " */
}

char *PrintCComment(Parser &p, char *comment, void *unused)
{
  printf("C Style Comment--------------------\n");
  printf("%s\n\n", comment);
  return comment;
}

char *PrintCPPComment(Parser &p, char *comment, void *unused)
{
  printf("C++ Style Comment------------------\n");
  printf("%s\n\n", comment);
  return comment;
}

